package com.hspedu.Homework;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author DL5O
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) throws IOException {
        //e:\mytemp 如果没有该文件夹，则创建该文件
        String directoryPath = "d:\\mytemp";
        File file = new File(directoryPath);
        if (file.exists()) {
            System.out.println(directoryPath + "该文件夹存在");
        } else {
            if (file.mkdirs()) {
                System.out.println("创建 " + directoryPath + " 创建成功");
            }
        }

        //创建该文件hello.txt
        String filePath = directoryPath + "\\hello.txt";
        File file2 = new File(filePath);
        if (!file2.exists()) {
            //创建文件
            if (file2.createNewFile()) {
                System.out.println(filePath + " 创建成功~");
                //写入hello，wrold;
                String s = "hello,world~";
                BufferedWriter bw = new BufferedWriter(new FileWriter(file2));
                bw.write(s);
                bw.close();
                System.out.println("写入成功！");
            } else {
                System.out.println(filePath + "创建失败~");
            }
        } else {
            System.out.println(filePath + " 已经存在，不再重复创建");
        }
    }
}
